import requests
from apscheduler.schedulers.blocking import BlockingScheduler
import datetime


def request_homepage():
    """定时请求首页"""
    try:
        # 设置请求头中的token
        headers = {"Authorization": "tayun123!"}

        # 发送GET请求
        response = requests.get("http://tayun-report.xmbita.com/", headers=headers)

        if response.status_code == 200:
            print(f"请求成功 - 状态码: {response.status_code}")
        else:
            print(f"请求失败 - 状态码: {response.status_code}")

    except Exception as e:
        print(f"请求出错: {str(e)}")


scheduler = BlockingScheduler()

# 添加定时任务,每小时的15分和45分执行
scheduler.add_job(
    request_homepage,
    "cron",
    minute="1,5,10,15,20,25,30,35,40,45,50,55,59",
    max_instances=100,
    misfire_grace_time=60,
    next_run_time=datetime.datetime.now(),
)

try:
    print(
        "开始执行定时任务,执行时间: 每小时的0分,5分,10分,15分,20分,25分,30分,35分,40分,45分,50分,55分,59分"
    )
    scheduler.start()
except (KeyboardInterrupt, SystemExit):
    pass
